//
//  BaseCollectionViewCell.m
//  GK
//
//  Created by Seven on 2019/1/17.
//  Copyright © 2019 Seven. All rights reserved.
//

#import "BaseCollectionViewCell.h"
#if GKKeyboardTarget
#import "GKSoundManager.h"
#endif

@implementation BaseCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self){
        self.clipsToBounds = YES;
        [self initViews];
    }
    return self;
}

- (void)initViews{
    
}

- (void)clickActionBtn{
    
}

- (UIView *)containerView{
    if (_containerView == nil) {
        self.containerView = [UIView initWithFrame:CGRectZero];
    }
    return _containerView;
}

- (BaseImageView *)image{
    if (_image == nil) {
        self.image = [BaseImageView initWithFrame:CGRectMake(15, 17, 45, 45)];
        _image.contentMode = UIViewContentModeScaleAspectFill;
    }
    return _image;
}

- (BaseLabel *)titleLbl{
    if (_titleLbl == nil) {
        self.titleLbl = [BaseLabel initWithFrame:CGRectMake(78, 24, 150, 19)];
        _titleLbl.font = [UIFont boldSystemFontOfSize:18];
        _titleLbl.textColor = COLOR_333333;
    }
    return _titleLbl;
}

- (BaseLabel *)subLbl{
    if (_subLbl == nil) {
        self.subLbl = [BaseLabel initWithFrame:CGRectMake(78, 46, 150, 13)];
        _subLbl.font = [UIFont systemFontOfSize:12];
        _subLbl.textColor = COLOR_999999;
    }
    return _subLbl;
}

- (UIButton *)actionBtn{
    if (_actionBtn == nil) {
        self.actionBtn = [UIButton initWithFrame:CGRectMake(0, 24, 95, 30)];
        [_actionBtn setTitleColor:ColorWithHex(0x6E3D00)];
        _actionBtn.titleLabel.font = BoldFontWithSize(14);
        [_actionBtn addTarget:self action:@selector(clickActionBtn)];
    }
    return _actionBtn;
}

- (void)setLineHidden:(BOOL)hidden{
    _lineView.hidden = hidden;
}
- (UIView *)lineView{
    if (_lineView==nil) {
        UIView *view = [UIView lineView];
        view.backgroundColor = COLOR_CUSTOM_LINE;
        [self.contentView addSubview:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.contentView);
            make.height.mas_equalTo(.5);
            make.right.equalTo(self.contentView).offset(-15);
            make.left.equalTo(self.contentView).offset(15);
        }];
        self.lineView = view;
    }
    return _lineView;
}



// 设置高亮效果
- (void)setHighlighted:(BOOL)highlighted{
    [super setHighlighted:highlighted];
    if (highlighted) {
        self.selected = YES;
        
#if GKKeyboardTarget
        if (_shouldPlaySound) {
            [GKSoundManager playeClickSond];
        }
#endif
        
    } else {
        [UIView animateWithDuration:0.1 delay:0.1 options:UIViewAnimationOptionCurveEaseOut animations:^{
            self.selected = NO;
        } completion:nil];
    }
}

@end
